﻿using System;
using System.Collections.Generic;
using Microsoft.SharePoint;

namespace ServBus.ListForm2010.Common.XSNOperator
{

    #region Abstract Class

    public abstract class BaseListInfo
    {
        #region Accessor

        public string ListTitle { get; set; }

        public string UniqueName { get; set; }

        public Guid ListID { get; set; }

        public List<BaseContentTypeInfo> ContentTypeInfoList { get; set; }

        #endregion
    }

    public class XListInfo : BaseListInfo
    {
        public XListInfo()
        {
            ContentTypeInfoList = new List<BaseContentTypeInfo>();
        }

        public void GenerateListInfo(SPList p_ListInfo)
        {
            ListID = p_ListInfo.ID;
            ListTitle = p_ListInfo.Title;
            UniqueName = p_ListInfo.Title.Replace(" ", "_");
        }

        public void AddContentTypeInfo(SPContentType p_ContentType)
        {
            ContentTypeInfo cTypeInfo = new ContentTypeInfo
            {
                ContentTypeId = p_ContentType.Id,
                ContentTypeName = p_ContentType.Name,
                UniqueName = (ListTitle + "_" + p_ContentType.Name).Replace(" ", "_")
            };

            foreach (SPField sField in p_ContentType.Fields)
            {
                XFieldInfo sFieldInfo = FieldInfoFactory.GetFieldInfoDefinition(sField, p_ContentType.Name);
                if (sFieldInfo != null)
                {
                    cTypeInfo.FieldInfoList.Add(sFieldInfo);
                }
            }
            ContentTypeInfoList.Add(cTypeInfo);
        }
    }

    #endregion
}